package com.xiaojie.sqlSession;

import com.xiaojie.config.XMLConfigBuider;
import com.xiaojie.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @ClassName SqlSessionFactoryBuilder
 * @Author jiege
 * @Date 2021/5/2 20:46
 **/
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException {
        //第一：使用dom4j解析配置文件，将解析出来的内容封装到Configuration中
        XMLConfigBuider xmlConfigBuider = new XMLConfigBuider();
        Configuration configuration = xmlConfigBuider.parseConfig(inputStream);


        //第二：创建sqlSessionFactory对象：工厂类：生产sqlSession：会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
